package model;

public class UserSession {

	private String username;
	private String password;
	private long credits;
	private boolean online;
	
	public UserSession(String username, String password, int credits) {
		this.username = username;
		this.password = password;
		this.credits = credits;
		this.online = false;
	}
	
	public String getUsername() {
		return this.username;
	}

	public long getCredits() {
		return this.credits;
	}
	
	public synchronized void addCredits(long credits) {
		this.credits += credits;
	}
	
	public synchronized void subtractCredits(long credits) {
		this.credits -= credits;
	}

	public synchronized void setOnline(boolean isOnline) {
		this.online = isOnline;
	}

	public boolean isOnline() {
		return this.online;
	}
	
	public boolean authenticate(String password) {
		return this.password.equals(password);
	}
	
	public UserInfo getUserInfo() {
		return new UserInfo(username, credits, online);
	}
}
